﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Art;
using System.Globalization;

namespace System.Windows.Elements
{
    [ValueConversion(typeof(Color), typeof(Decimal))]
    class ClassicChannelSplitter : IValueConverter
    {
        private readonly ColorChannel channel;
        private readonly ColorAccumulator accumulator;

        public ClassicChannelSplitter(ColorChannel channel, ColorAccumulator accumulator)
        {
            this.channel = channel;
            this.accumulator = accumulator;
        }

        public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
        {
            return (Decimal)accumulator.GetClassicValue(channel);
        }

        public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture)
        {
            var color = this.accumulator.GetColor(this.channel.Owner);
            color.SetClassicValue(this.channel, System.Convert.ToDouble(value, CultureInfo.CurrentCulture));
            return color;
        }
    }
}
